package com.qian.service.ddj.listener;

import com.qian.api.ddj.model.LoginLog;
import com.qian.api.ddj.service.ILoginLogService;
import com.yaowk.api.system.event.LoginEvent;
import com.yaowk.api.system.model.Login;
import com.yaowk.api.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Component
public class LoginListener implements ApplicationListener<LoginEvent> {
    @Autowired
    private ILoginLogService loginLogService;
    @Autowired
    private IUserService userService;

    @Override
    public void onApplicationEvent(LoginEvent loginEvent) {
        Login login = loginEvent.getSource();
        LoginLog loginLog = new LoginLog();
        loginLog.setUserId(login.getUserId().intValue());
        loginLog.setCreateTime(login.getTime());
        loginLog.setIp(login.getIp());
        loginLogService.simpleSave(loginLog);
    }
}
